<%@page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="html" tagdir="/WEB-INF/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html>
<html>
<html:header title="新增销售单">

    <link rel="stylesheet" href="${baseUrl}css/public.css" media="all">

    <style type="text/css">

        .save{
            cursor:pointer;
        }

        .layui-table-cell {
            overflow: visible !important;
        }
        /* 使得下拉框与单元格刚好合适 */
        td .layui-form-select{
            margin-top: -10px;
            margin-left: -15px;
            margin-right: -15px;
        }
    </style>

    <script>
        jQuery(function () {
            fixTableOperatorButton();
            $(window).focus();
            window.addEventListener("keydown", function(e) {
                if (e.keyCode == 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
                    $("#save").click();
                    e.preventDefault();
                }else if (e.keyCode == 119){
                    $("#depositAmt").focus();
                    scrollToElement($("#depositAmt"));
                    e.preventDefault();
                }

            }, false);

            if (_businessSet.saleTaxRateFlag) {
                $("#tax").parent().css("display","inline-block");
            }

            getByType("${baseUrl}",ORDER_TYPE.XSD.type, $("[name='no']"));

            ajaxSelect("${baseUrl}organization/store/getStores.action","storeId");

            ajaxSelect("${baseUrl}user/user/getAll.action","userId");
            ajaxSelect("${baseUrl}settAccount/settAccount/listVo.action","settAccountId");

            $("#cancel").click(function () {
                closeSubIframe();
            });

            $(".save").click(function () {
                $("#save").click();
            });
            $("#save").click(function () {
                $("[lay-filter='save']").click();
            });

            $("[name='date']").val(GMTToDate(new Date()));
            $("[name='deliveryDate']").val(GMTToDate(new Date()));


            $(".select-goods").click(function () {
                let houseId = $("[name='houseId']").val();
                if (houseId == ""){
                    errTip("请选择出库仓库");
                    return;
                }
                let url = "${baseUrl}select/selectGoods.action?houseId="+houseId+"&priceFlag=3";
                if (_businessSet.houseInOut == "" || _businessSet.houseInOut == "false"){
                    url += "&numberBar=2&checkStock=1";
                }
                openBigHtmlDialog("选择商品", url);
            });


            $(".select-packet").click(function () {
                let houseId = $("[name='houseId']").val();
                if (houseId == ""){
                    errTip("请选择出库仓库");
                    return;
                }
                let url = "${baseUrl}select/selectPacket.action?houseId="+houseId;
                if (_businessSet.houseInOut == "" || _businessSet.houseInOut == "false"){
                    url += "&checkStock=1";
                }

                openBigHtmlDialog("选择套餐", url);
            });

            $(".select-template").click(function () {
                let houseId = $("[name='houseId']").val();
                if (houseId == ""){
                    errTip("请选择出库仓库");
                    return;
                }

                let url = "${baseUrl}select/selectGoodsTemplate.action?houseId="+houseId;
                if (_businessSet.houseInOut == "" || _businessSet.houseInOut == "false"){
                    url += "&checkStock=1";
                }

                openBigHtmlDialog("选择模板", url);
            });
        });

        layui.use(['form', 'table', 'laydate'], function () {
            let $ = layui.jquery,
                form = layui.form,
                table = layui.table,
                laydate = layui.laydate,
                util = layui.util;

            laydate.render({
                elem: '#deliveryDate'
            });
            laydate.render({
                elem: '#date'
            });

            get("${baseUrl}sale/saleOrder/getVoById.action?id=${saleOrderId}", function (res) {
                if (res.code == 1) {
                    let data = res.data;
                    $("#custom").val(data.custom.name);
                    $('[name="customId"]').val(data.custom.id);

                    let formData = {};
                    formData.type = res.data.type;
                    formData.delivery = res.data.delivery;
                    formData.remark = res.data.remark;
                    if (formData.delivery){
                        $("#sendInfo").css("display","block");
                        if (res.data.deliveryDate != null) {
                            formData.deliveryDate = GMTToDate(res.data.delivery);
                        }
                        if (res.data.contacts != null) {
                            formData.contacts = res.data.contacts;
                        }
                        if (res.data.phone != null) {
                            formData.phone = res.data.phone;
                        }
                        if (res.data.address != null) {
                            formData.address = res.data.address;
                        }
                    }

                    if (res.data.discountFlag == 1) {
                        formData.discountFlag = 1;
                        formData.discountRate = res.data.discountRate;
                        $("#discountRate").css("display","block");
                        $("#discountAmt").css("display","none");
                    } else {
                        formData.discountFlag = 2;
                        formData.discountAmt = getPrice(res.data.discountAmt);
                        $("#discountRate").css("display","none");
                        $("#discountAmt").css("display","block");
                    }
                    formData.otherAmt = getPrice(res.data.otherAmt);
                    formSetVal("sale",formData);

                    ajaxSelect("${baseUrl}organization/house/getHouseByStore.action?storeId="+res.data.storeId,"houseId");


                    let list=[];
                    $.each(data.saleOrderGoodsVoList, function (i,d) {
                        if (d.waitNumber > 0) {
                            let vo = d.goodsVo;
                            vo.saleOrderGoodsId = d.id;
                            vo.goodsId = d.goodsId;
                            vo.number = d.waitNumber;
                            vo.waitNumber = d.waitNumber;
                            vo.price = d.price;
                            vo.unitId = d.unitId;
                            vo.times = d.times;
                            vo.amount = d.amount;
                            vo.remark = d.remark;
                            list.push(vo);
                        }
                    });

                    $.each(data.saleOrderPacketVoList, function (i,d) {
                        if (d.waitNumber > 0) {
                            let vo = d;
                            vo.saleOrderPacketId = d.id;
                            vo.packetId = d.packetId;
                            vo.name = d.packetName;
                            vo.no = d.packetNo;
                            vo.number = d.waitNumber;
                            vo.waitNumber = d.waitNumber;
                            vo.price = d.price;
                            vo.amount = d.amount;
                            vo.remark = d.remark;
                            list.push(vo);
                        }
                    });
                    renderTable(list);
                }else {
                    errTip("获取订单信息失败");
                }
            });


            $("#discountAmt").val(getPrice("0"));
            $("#otherAmt").val(getPrice("0"));
            $("#totalAmount").html(getPrice("0"));
            $("#depositAmt").val(getPrice("0"));

            $("#discountRate").blur(function () {
                $(this).val(genDiscountRate($(this).val()));
                setTotalAmount();
                processTotalRow();
            });

            $("#discountAmt").blur(function () {
                let amt = genAmount($(this).val());
                let totalAmount = parseFloat($("#totalAmount").html());
                if (amt > totalAmount){
                    $(this).val(getPrice("0"));
                    tip("折扣金额不能大于总计金额");
                }else{
                    $(this).val(getPrice(amt));
                }
                setTotalAmount();
                processTotalRow();
            });

            $("#otherAmt").blur(function () {
                let amt = genAmount($(this).val());
                $(this).val(getPrice(amt));
                setTotalAmount();
                processTotalRow();
            });

            form.on('switch(delivery)', function(data){
                if (this.checked){
                    $("#sendInfo").css("display","block");
                } else {
                    $("#sendInfo").css("display","none");
                }
            });

            // 监听修改update到表格中
            form.on('select(unitSelect)', function (data) {
                let index = $(data.elem).parents('tr').data('index');
                let tableData = layui.table.cache.table;
                let goodsUnitVo = genUnitVo(tableData[index].goodsUnitVoList, data.value);
                $(data.elem).parents('tr').find(".price").val(getPrice(goodsUnitVo.wholesalePrice));
                $(data.elem).parents('tr').find(".wholesalePrice").html("批发价："+getPrice(goodsUnitVo.wholesalePrice));
                $(data.elem).parents('tr').find(".wholesalePrice").attr("price",getPrice(goodsUnitVo.wholesalePrice));
                $(data.elem).parents('tr').find(".retailPrice").html("零售价："+getPrice(goodsUnitVo.retailPrice));
                $(data.elem).parents('tr').find(".retailPrice").attr("price",getPrice(goodsUnitVo.retailPrice));

                tableData[index].unitId = data.value;
                tableData[index].times = goodsUnitVo.times;
                tableData[index].price = goodsUnitVo.wholesalePrice;
                processAmount($(data.elem));
                processTotalRow();
            });

            form.on('select(discountFlag)', function (data) {
                $("#totalAmount").attr("discountFlag",data.value);
                if (data.value == '1'){
                    $("#discountRate").css("display","block");
                    $("#discountAmt").css("display","none");
                } else {
                    $("#discountRate").css("display","none");
                    $("#discountAmt").css("display","block");
                }
            });

            form.verify({
                settAccountId: function(value, item){ //value：表单的值、item：表单的DOM对象
                    if(value == null || value==""){
                        return '结算账户不能为空';
                    }
                },
                custom: function(value, item){ //value：表单的值、item：表单的DOM对象
                    if(value == null || value==""){
                        return '客户不能为空';
                    }
                },
                userId: function(value, item){ //value：表单的值、item：表单的DOM对象
                    if(value == null || value==""){
                        return '经办人不能为空';
                    }
                },
                date: function(value, item){ //value：表单的值、item：表单的DOM对象
                    if(value == null || value==""){
                        return '业务日期不能为空';
                    }
                },
                deliveryDate: function(value, item){ //value：表单的值、item：表单的DOM对象
                    if(isSend() && (value == null || value=="")){
                        return '送货日期不能为空';
                    }
                },
                contacts: function(value, item){ //value：表单的值、item：表单的DOM对象
                    if(isSend() && (value == null || value=="")){
                        return '联系人不能为空';
                    }
                },
                phone: function(value, item){ //value：表单的值、item：表单的DOM对象
                    if(isSend() && (value == null || value=="")){
                        return '联系电话不能为空';
                    }
                },
                address: function(value, item){ //value：表单的值、item：表单的DOM对象
                    if(isSend() && (value == null || value=="")){
                        return '地址不能为空';
                    }
                },
            });


            form.on('submit(save)',function (data) {
                if (table.cache.table.length == 0) {
                    tip("未选择任何商品");
                    return false;
                }

                if (data.field.houseId == ""){
                    errTip("仓库不能为空");
                    return false;
                }

                if (data.field.customId == ""){
                    errTip("客户不能为空");
                    return false;
                }

                let tableData = table.cache.table;

                for (let i=0;i<tableData.length;i++) {
                    let vo = tableData[i];
                    let isGoods = vo.packetId == undefined || vo.packetId == null ? true:false;
                    let tipTitle = isGoods ? "商品" : " 套餐";

                    if (vo.sn && (_businessSet.houseInOut == "" || _businessSet.houseInOut == "false")) {
                        if (vo.goodsSnList == undefined || vo.goodsSnList.length==0) {
                            errTip("商品("+vo.name + ")的序列号数量不能为0");
                            return ;
                        } else if(tableData[i].goodsSnList.length != tableData[i].number) {
                            errTip("商品("+tableData[i].name + ")的序列号数量与数量不一致");
                            return ;
                        }
                    } else {
                        if (vo.number == 0) {
                            errTip(tipTitle + "("+vo.name + ")的数量不能为0");
                            $("tr[data-index='"+i+"']").find(".number").css("border-color","red");
                            return ;
                        }
                    }

                    if (vo.number > vo.waitNumber) {
                        errTip(tipTitle + "("+vo.name + ")的数量不能大于待转销售数量("+vo.waitNumber+")");
                        $("tr[data-index='"+i+"']").find(".number").css("border-color","red");
                        return ;
                    }
                }

                let sale = data.field;
                sale.totalAmt = $("#totalAmount").html();
                sale.date = genDate(sale.date);

                if (_businessSet.saleTaxRateFlag){
                    sale.tax = $("#tax").html();
                }

                if (data.field.delivery == undefined) {
                    sale.delivery = false;
                    sale.deliveryDate = "";
                    sale.contacts = "";
                    sale.phone = "";
                    sale.address = "";
                } else {
                    sale.delivery = true;
                    sale.deliveryDate = genDate(sale.deliveryDate);
                }

                if (data.field.ticket == undefined) {
                    sale.ticket = 1;
                } else {
                    sale.ticket = 2;
                }

                if (data.field.discountFlag == '1') {
                    sale.discountAmt = "";
                } else {
                    sale.discountRate = "";
                }

                sale.image = getImageNames();

                let saleGoodsVoList = [];
                let salePacketVoList = [];
                $.each(table.cache.table,function (i,d) {
                    if (!emptyEntity(d.goodsId)) {
                        let vo = {};
                        vo.saleOrderGoodsId = d.saleOrderGoodsId;
                        vo.goodsId = d.goodsId;
                        vo.unitId = d.unitId;
                        vo.times = d.times;
                        vo.number = d.number;
                        vo.price = d.price;
                        vo.amount = d.amount;
                        vo.remark = d.remark;
                        vo.goodsSnList = genUploadTableList(d.goodsSnList);
                        saleGoodsVoList.push(vo);
                    } else {
                        let vo = {};
                        vo.saleOrderPacketId = d.saleOrderPacketId;
                        vo.packetId = d.packetId;
                        vo.packetName = d.name;
                        vo.packetNo = d.no;
                        vo.number = d.number;
                        vo.price = d.price;
                        vo.amount = d.amount;
                        vo.remark = d.remark;

                        let packetGoodsVoList = [];
                        $.each(d.packetGoodsVoList,function (i,pg) {
                            packetGoodsVoList.push({
                                packetId : pg.packetId,
                                goodsId : pg.goodsId,
                                unitId:pg.unitId,
                                times:pg.times,
                                number:pg.number,
                                price:pg.price,
                                amount:pg.amount,
                            });
                        });

                        vo.packetGoodsVoList = packetGoodsVoList;
                        salePacketVoList.push(vo);
                    }

                });

                sale.saleGoodsVoList = saleGoodsVoList;
                sale.salePacketVoList = salePacketVoList;



                delete sale.storeId;
                delete sale.custom;
                delete sale.number;
                delete sale.unitId;
                delete sale.amount;
                delete sale.price;
                console.log(JSON.stringify(sale));
                tipLoad("销售单新增中...");

                post("${baseUrl}sale/sale/add.action", sale, function (res) {
                    closeAll();
                    if (res.code == 1) {
                        tip(res.msg);


                        if (_businessSet.quickPrint) {
                            //销售快速打印
                            document.getElementById("printFrame").contentWindow.printPage(res.data);
                        }

                        setTimeout(function () {
                            refreshHouseWaitOut();
                            refreshMainIframe("${baseUrl}sale/saleOrder.action");
                            refreshMainIframe("${baseUrl}sale/sale.action");
                            closeSubIframe();
                        },800);
                    } else {
                        errTip(res.msg);
                    }
                });
                return false;
            });
        });

        function renderTable(list) {
            layui.table.render({
                id:'table',
                elem: '#table',
                height:300,
                data:list,
                totalRow:true,
                text: {
                    none: '未选择商品' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
                },
                cols: [[
                    {type:'numbers'},
                    {field: 'name', minWidth: 140, title: '名称/规格',style:"font-size:12px;",templet:'#nameBar'},
                    {field: 'no', width: 140, title: '商品编号',style:"font-size:12px;"},
                    {field:'number', width: 110, title: '数量',templet:"#numberBar"},
                    {width: 120, title: '单位',style:"font-size:12px;", templet:function (d) {
                            return d.goodsId == null ? "" : genUnitName(d.goodsUnitVoList,d.unitId);
                        }},
                    {field: 'price', width: 120, title: '单价',templet:'#priceBar'},
                    {field: 'amount', width: 120, title: '金额',style:"font-size:12px;",templet:"#amountBar"},
                    {width: 110, title: '序列号',templet: "#snNumberBar"},
                    {field: 'remark', width: 120, title: '备注',style:"font-size:12px;",edit:"text"},
                    {title: '操作', minWidth: 70, fixed:'right', templet: '#operBar'},
                ]],
                limit: Number.MAX_VALUE,
                done: function(res, curr, count){
                    $(".packetName").unbind().bind('click',function () {
                        let index = $(this).parents('tr').data('index');
                        let tableData = layui.table.cache.table;
                        showPacketList(tableData[index].name, tableData[index].packetGoodsVoList);
                    });
                    $(".snNumberDiv").unbind().bind('click',function () {
                        let index = $(this).parents('tr').data('index');
                        let tableData = layui.table.cache.table;
                        showSnList(tableData[index].name, tableData[index].goodsSnList);
                    });

                    $(".priceDiv").unbind("mouseenter").bind("mouseenter", function() {
                        $(this).find(".priceListDiv").css("display","block");
                    });
                    $(".priceDiv").unbind("mouseleave").bind("mouseleave", function() {
                        $(this).find(".priceListDiv").css("display","none");
                    });

                    $(".subjectPrice").unbind("click").bind("click", function () {
                        $(this).parents(".priceDiv").find(".priceListDiv").css("display","none");
                        let price = $(this).attr("price");
                        $(this).parents(".priceDiv").find(".price").val(price);

                        let index = $(this).parents('tr').data('index');
                        let tableData = layui.table.cache.table;
                        tableData[index].price = price;
                        processAmount($(this));
                        processTotalRow();
                    });

                    $(".price").unbind("blur").bind("blur",function () {
                        $(this).val(getPrice($(this).val()));
                        let index = $(this).parents('tr').data('index');
                        let tableData = layui.table.cache.table;
                        tableData[index].price = getPrice($(this).val());
                        processAmount($(this));
                        processTotalRow();
                    });

                    $(".amount").blur(function () {
                        setAmount(genAmount($(this).val()), $(this));
                        processTotalRow();
                    });

                    $(".number").unbind("blur").bind("blur",function () {
                        let $input=$(this);
                        let number = genNumber($input.val());
                        checkNumber(number,$input);
                        processNumber(number, $input);
                        processTotalRow();
                    });

                    $(".numberSn").unbind("click").bind("click",function () {
                        snIndex = $(this).parents('tr').data('index');
                        let goodsId = layui.table.cache.table[snIndex].goodsId;
                        console.log("houseId:${houseId}");
                        console.log("goodsId:"+goodsId);
                        let houseId = $("[name='houseId']").val();
                        if (houseId == "" ) {
                            errTip("请选择仓库");
                            return;
                        }
                        openHtmlDialog("管理序列号","${baseUrl}dialog/sn/select.action?type=2&houseId="+houseId+"&goodsId="+goodsId, function (layero, index) {
                            var iframe = window[layero.find('iframe')[0]['name']];
                            let goodsSnList = layui.table.cache.table[snIndex].goodsSnList;
                            if (emptyList(goodsSnList)) {
                                goodsSnList=[];
                            }
                            iframe.setDataToTable(goodsSnList,genGoodsSnMap(layui.table.cache.table));
                        });
                    });

                    setTotalAmount();
                    processTotalRow();
                }
            });

            layui.table.on('tool(table)', function (obj) {
                if (obj.event === 'delete') {
                    operator_del(obj);
                }
            });

            function checkNumber(number,$input) {
                let index = $input.parents('tr').data('index');
                let tableData = layui.table.cache.table;
                let vo = tableData[index];
                let maxNumber = vo.maxNumber;

                if (number == 0) {
                    tip("数量必须大于0");
                    $input.css("border-color","red");
                } else if(maxNumber!=undefined && number > maxNumber){
                    tip("不能大于剩余退货数量");
                    $input.css("border-color","red");
                } else if(vo.waitNumber < number) {
                    tip("的数量不能大于待转销售数量("+vo.waitNumber+")");
                    $input.css("border-color","red");
                } else {
                    $input.css("border-color","#ffffff");
                }
            }
        }

        /**
         *当仓库改变时会回调这个函数
         */
        function houseChange(houseId,oldHouseId) {
            $(window).focus();
            if (oldHouseId != "" && layui.table.cache.table.length > 0) {
                let flag = 1;
                $.each(layui.table.cache.table, function (i,d) {
                    if (d.goodsSnList != null) {
                        d.goodsSnList = null;
                        flag=2;
                    }
                });

                renderTable(layui.table.cache.table);
                if (flag == 2) {
                    tip("仓库修改,序列号被清空");
                }
            }
        }

        /**
         * 如果使用商品选择窗口，必须实现此函数，否则取不到已选择的商品数据
         * @param data
         */
        function getSelectGoods(data) {
            console.log("选择商品数据");
            //处理显示数据
            $.each(data,function (i,d) {
                d.goodsId = d.id;
                layui.table.cache.table.push(d);
            });

            reloadGoodsTable();
            $(window).focus();
        }

        /**
         * 如果使用商品模板选择窗口，必须实现此函数，否则取不到已选择的商品模板数据
         * @param data
         */
        function getSelectTemplate(data) {
            //处理显示数据
            $.each(data,function (i,d) {
                d.goodsId = d.id;
                layui.table.cache.table.push(d);
            });

            reloadGoodsTable();
            $(window).focus();
        }

        /**
         * 如果使用套餐选择窗口，必须实现此函数，否则取不到已选择的套餐数据
         * @param data
         */
        function getSelectPacket(data) {
            //处理显示数据
            $.each(data,function (i,d) {
                d.packetId = d.id;
                layui.table.cache.table.push(d);
            });

            reloadGoodsTable();
            $(window).focus();
        }


        /**
         * 必须实现，供根据条码或编号取得商品信息所调用
         * @param data
         */
        function processGoods(data) {
            $(window).focus();
            let houseId = $('[name="houseId"]').val();
            if (houseId==''){
                errTip('请先选择出库仓库');
                return;
            }

            layui.table.cache.table.push(data);
            reloadGoodsTable();
        }

        /**
         * 开启sn号的商品，会回调这个函数
         *
         */
        function processSnSelect(data) {
            layui.table.cache.table[snIndex].number = data.length;
            layui.table.cache.table[snIndex].goodsSnList = data;
            let child = data.length + '个';
            $("tr[data-index='"+snIndex+"']").find(".snNumberDiv").html(child);
            processNumber(data.length, $("tr[data-index='"+snIndex+"']").find(".number"));
            processTotalRow();
            $(window).focus();
        }


        //是否送货
        function isSend() {
            let temp = $('[name="delivery"]').next().find("em").html();
            if (temp == '是'){
                return true;
            }
            return false;
        }

        function processTotalRow() {
            let amount=0;
            let number = 0;
            $.each(layui.table.cache.table, function (i,d) {
                number += parseInt(d.number);
                amount += parseFloat(d.amount);
            });
            setTotalRowWithCenter("amount",getPrice(amount));
            setTotalRowWithCenter("number",number);
            setTotalRow("1","合计");
        }
    </script>

</html:header>
<iframe id="printFrame" style="width:0px;height:0px" src="${baseUrl}print/salePrint.action" frameborder="0"></iframe>
<body>
<div style="width: 100%; margin-bottom: 20px;overflow: hidden;" >
    <button id="save" class="layui-btn">保存</button>
    <button class="layui-btn layui-btn-primary" id="cancel">取消</button>
</div>

<div class="layuimini-container">
    <div class="layuimini-main">

        <h2 class="tableBeforeTitle">销售单</h2>
        <div style="height: 4px;background-color: #bbbbbb;width: 100%;margin: 20px 0 2px 0;"></div>
        <div style="height: 1px;width: 100%;background-color: #dddddd;margin-bottom: 10px;"></div>
        <div style="height: 10px;"></div>


        <form class="layui-form" action="" lay-filter="sale">
            <input type="hidden" name="saleOrderId" value="${saleOrderId}">
            <input type="hidden" name="close" value="false">
            <input type="hidden" name="customId">
            <input type="hidden" name="afterDiscountAmt" id="afterDiscountAmt">
            <button style="display: none;" lay-submit lay-filter="save" class="layui-btn">保存</button>

            <div class="layui-form-item">

                <div class="layui-inline" style="margin-bottom: 4px;">
                    <div class="label">编号</div>
                    <div style="display: inline-block;width: 160px;">
                        <input type="text" id="no" name="no" class="layui-input readonly" readonly style="font-size: 12px;">
                    </div>
                </div>


<%--                <html:selectHouse label="出库仓库" showDefault="1"/>--%>

                <div class="layui-inline" style="margin-bottom: 4px;">
                    <div class="label">出库仓库</div>
                    <div style="display: inline-block;width: 160px;">
                        <select name="houseId">
                        </select>
                    </div>
                </div>

                <div class="layui-inline" style="margin-bottom: 4px;">
                    <div class="label">客户</div>
                    <div style="display: inline-block;width: 160px;">
                        <input type="text" id="custom" name="custom" class="layui-input readonly" readonly style="font-size: 12px;">
                    </div>
                </div>

                <div class="layui-inline" style="margin-bottom: 4px;">
                    <div class="label">销售类型</div>
                    <div style="display: inline-block;width: 160px;">
                        <select name="type">
                            <option value="1">批发</option>
                            <option value="2">销售</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline" style="margin-bottom: 4px;">
                    <div class="label">业务日期</div>
                    <div style="display: inline-block;width: 160px;">
                        <input type="text" name="date" id="date" lay-verify="date" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline" style="margin-bottom: 4px;">
                    <div class="label">经手人</div>
                    <div style="display: inline-block;width: 160px;">
                        <select name="userId" lay-verify="userId" lay-filter="userId">
                        </select>
                    </div>
                </div>


                <div class="layui-inline" style="margin-bottom: 4px;">
                    <div class="label">送货</div>
                    <div style="display: inline-block;width: 160px;">
                        <input type="checkbox" name="delivery" lay-skin="switch" lay-filter="delivery" lay-text="是|否">
                    </div>
                </div>

                <div class="layui-inline" style="margin-bottom: 4px;">
                    <div class="label">需要发票</div>
                    <div style="display: inline-block;width: 160px;margin-top: -10px;">
                        <input type="checkbox" name="ticket" lay-skin="switch" lay-filter="ticket" lay-text="是|否">
                    </div>
                </div>
            </div>

            <div id="sendInfo" style="display: none;border: 1px #eeeeee solid;padding: 10px;margin-bottom: -10px;background-color: #eeeeee">
                <div class="layui-inline" style="margin-bottom: 4px;">
                    <div class="label">送货日期</div>
                    <div style="display: inline-block;width: 160px;">
                        <input type="text" name="deliveryDate" id="deliveryDate" lay-verify="deliveryDate" placeholder="送货日期" autocomplete="off" class="layui-input">
                        </select>
                    </div>
                </div>

                <div class="layui-inline" style="margin-bottom: 4px;">
                    <div class="label">客户联系人</div>
                    <div style="display: inline-block;width: 160px;">
                        <input type="text" name="contacts" id="contacts" lay-verify="contacts" class="layui-input">
                        </select>
                    </div>
                </div>

                <div class="layui-inline" style="margin-bottom: 4px;">
                    <div class="label">联系电话</div>
                    <div style="display: inline-block;width: 160px;">
                        <input type="text" name="phone" id="phone" lay-verify="phone" class="layui-input">
                        </select>
                    </div>
                </div>

                <div class="layui-inline" style="margin-bottom: 4px;">
                    <div class="label">送货地址</div>
                    <div style="display: inline-block;width: 160px;">
                        <input type="text" name="address" id="address" lay-verify="address" class="layui-input">
                        </select>
                    </div>
                </div>
            </div>

            <table class="layui-hide" id="table" lay-filter="table" lay-size="sm"></table>
            <div style="overflow: auto;margin-top: -10px">
                <table class="layui-table" style="min-width:600px;margin: 0px 0 0 0;">
                    <colgroup>
                        <col>
                        <col width="300">
                    </colgroup>
                    <tbody>
                    <tr>
                        <td>
                            <div style="float: right;">
                                <div class="layui-inline">
                                    <div style="display: inline-block;width: 80px;">
                                        <select name="discountFlag" lay-filter="discountFlag">
                                            <option value="1">折扣率(%)</option>
                                            <option value="2">折扣额(元)</option>
                                        </select>
                                    </div>
                                    <div class="bottomContent" style="margin-left: 12px;">
                                        <input type="number" name="discountRate" id="discountRate" value="100" class="layui-input no-border" style="padding-left: 4px;">
                                        <input type="number" name="discountAmt" id="discountAmt" value="0" class="layui-input no-border" style="display: none;padding-left: 4px;">
                                    </div>
                                </div>

                                <div class="layui-inline" style="text-align: left; width: 100px;display: none;margin-right: 20px;">
                                    折后税额<span id="tax" style="padding-left: 10px;">0.00</span>
                                </div>

                                <div class="layui-inline">
                                    <div class="bottomLabel">其他费用</div>
                                    <div class="bottomContent">
                                        <input type="number" name="otherAmt" id="otherAmt" value="100" class="layui-input no-border" style="padding-left: 4px;">
                                    </div>
                                </div>
                            </div>
                        </td>

                        <td style="background-color: #FFFFCC;">
                            <div style="display: inline-block;height: 38px;line-height: 38px;width: 80px;">结算账户</div>
                            <div class="layui-input-inline" style="margin: 10px 15px 0px 15px;width: 130px;">
                                <select name="settAccountId" lay-filter="settAccountId">
                                </select>
                            </div>
                        </td>
                    </tr>

                    <tr>
                        <td>
                            <div style="text-align: right;font-size:16px;font-weight:bold;height: 38px;line-height: 38px;padding-right: 60px;">
                                总计金额:<span id="totalAmount" discountFlag="1" style="color: #FF5722">0</span>元
                            </div>
                        </td>

                        <td style="background-color: #FFFFCC;max-width: 300px;">
                            <div style="display: inline-block;height: 38px;line-height: 38px;width: 80px;">实收金额</div>
                            <div class="layui-input-inline" style="width: 160px;">
                                <input type="number" id="realAmt" name="realAmt" class="layui-input" >
                            </div>
                        </td>
                    </tr>

                    <tr>
                        <td>
                            <div style="position: relative;">
                                <input type="text" id="remark" name="remark" class="layui-input no-border" style="padding-left: 60px;">
                                <div style="position: absolute;top: 10px;left: 10px;">
                                    备注:
                                </div>
                            </div>
                        </td>
                        <td class="save" style="background-color: #1E9FFF;color:#ffffff;text-align: center;font-size: 16px;">保存(ctrl+s)</td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </form>

        <div class="layui-form-item" style="padding-top: 20px;">
            <label class="layui-form-label">图片附件</label>
            <html:imageAnnex type="sale" update="false"
                             uploadUrl="${baseUrl}sale/sale/uploadImg.action"
                             updateUrl="${baseUrl}sale/sale/updateImage.action"/>
        </div>
    </div>

    <script type="text/html" id="operBar">
        <a class="layui-btn layui-btn-xs layui-btn-danger table-operator" lay-event="delete">删除</a>
    </script>

    <script type="text/html" id="nameBar">
        {{#  if(d.packetId != undefined && d.packetId != null){ }}
        <div class="packetName">
            {{d.name}}
        </div>
        {{#  }else{ }}
        {{genGoodsName(d.name,d.norms)}}
        {{#  } }}
    </script>

    <script type="text/html" id="numberBar" >
        <div class="numberDiv">
            {{# if(d.sn==true && (_businessSet.houseInOut == "" || _businessSet.houseInOut == "false")){ }}
            <span class="number">{{ getNumber(d.number) }}</span>
            <span class="numberSn">sn</span>
            {{# }else{ }}
            <input type="number" name="number" class="layui-input number" value="{{ getNumber(d.number) }}" style="background: #ffffff">
            {{# } }}
        </div>
    </script>

    <script type="text/html" id="snNumberBar" >
        {{# if(d.sn==true && (_businessSet.houseInOut == "" || _businessSet.houseInOut == "false")){ }}
        {{# if(d.goodsSnList!=null && d.goodsSnList.length > 0){ }}
        <div class="snNumberDiv">{{d.goodsSnList.length}}个</div>
        {{# }else{ }}
        <div class="snNumberDiv">0个</div>
        {{# } }}
        {{# } }}
    </script>

    <script type="text/html" id="amountBar" >
        <div class="numberDiv">
            <input type="number" name="amount" value="{{ getPrice(d.amount) }}" class="layui-input amount">
        </div>
    </script>

    <script type="text/html" id="priceBar" >
        <div class="priceDiv">
            <input type="number" name="price" value="{{ getPrice(d.price) }}" class="layui-input price">

            {{#  if(d.packetId==undefined) {  }}
            <div class="priceListDiv">
                <ul>
                    {{# if(d.unitId!=undefined){ }}
                    <li class="subjectPrice retailPrice" price="{{ getPrice(genUnitVo(d.goodsUnitVoList,d.unitId).retailPrice) }}">
                        零售价:{{ getPrice(genUnitVo(d.goodsUnitVoList,d.unitId).retailPrice) }}
                    </li>
                    <li class="subjectPrice wholesalePrice" price="{{ getPrice(genUnitVo(d.goodsUnitVoList,d.unitId).wholesalePrice) }}">
                        批发价:{{ getPrice(genUnitVo(d.goodsUnitVoList,d.unitId).wholesalePrice) }}
                    </li>
                    {{# } }}
                </ul>
            </div>
            {{#  } }}
        </div>
    </script>
</div>

</body>
<html:packetListDialog/>
<html:snListDialog/>
<html:loading/>
</html>